using DiLu.Expansion.File.Operates.Minio.Configs;
using Minio;

namespace DiLu.Expansion.File;

public static partial class DiLuFileExpansion
{
    /// <summary>
    ///     构建文件流保存到Minio的配置
    /// </summary>
    /// <param name="fileStream">文件流</param>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件组名称</param>
    /// <param name="fileExtension">文件扩展名</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <returns></returns>
    public static SaveFileStreamToMinioConfig BuildSaveFileStreamToMinioConfig(this Stream fileStream,
        string rootDirectory, string fileGroupName, string fileExtension, IMinioClient minioClient, string bucketName)
    {
        return new SaveFileStreamToMinioConfig(rootDirectory, fileGroupName, fileStream, fileExtension, minioClient, bucketName);
    }

    /// <summary>
    ///     构建获取FTP文件的配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="fileRelativePath">文件相对路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <returns></returns>
    public static GetMinioFileStreamConfig BuildGetMinioFileConfig(this string fileRelativePath,
        string rootDirectory, string fileGroupName, IMinioClient minioClient, string bucketName)
    {
        return new GetMinioFileStreamConfig(rootDirectory, fileGroupName, fileRelativePath, minioClient, bucketName);
    }

    /// <summary>
    ///     构建获取Minio文件的配置
    /// </summary>
    /// <param name="fileFullPath">文件完整路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <returns></returns>
    public static GetMinioFileStreamConfig BuildGetMinioFileConfig(this string fileFullPath,
        IMinioClient minioClient, string bucketName)
    {
        return new GetMinioFileStreamConfig(fileFullPath, minioClient, bucketName);
    }

    /// <summary>
    ///     构建删除Minio文件的配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="fileRelativePath">文件相对路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <returns></returns>
    public static DeleteMinioFileConfig BuildDeleteMinioFileConfig(this string fileRelativePath,
        string rootDirectory, string fileGroupName, IMinioClient minioClient, string bucketName)
    {
        return new DeleteMinioFileConfig(rootDirectory, fileGroupName, fileRelativePath,
            minioClient, bucketName);
    }

    /// <summary>
    ///     构建删除Minio文件的配置
    /// </summary>
    /// <param name="fileFullPath">文件完整路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <returns></returns>
    public static DeleteMinioFileConfig BuildDeleteMinioFileConfig(this string fileFullPath,
        IMinioClient minioClient, string bucketName)
    {
        return new DeleteMinioFileConfig(fileFullPath, minioClient, bucketName);
    }

    /// <summary>
    ///     构建搜索Minio文件夹的配置
    /// </summary>
    /// <param name="rootDirectory">根目录</param>
    /// <param name="fileGroupName">文件分组名称</param>
    /// <param name="directoryRelativePath">目录相对路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <param name="searchOption">搜索选项</param>
    /// <param name="searchPattern">
    ///     模糊查询模式，默认匹配所有文件
    ///     如果想查询指定类型文件使用 ^([\s\S]+)(\.(jpg|png))$
    ///     如果想模糊查询文件使用  ^([\s\S]*)name([\s\S]*)(\.\w+)$
    /// </param>
    /// <returns></returns>
    public static SearchMinioFileConfig BuildSearchMinioFileConfig(this string rootDirectory,
        string fileGroupName, string directoryRelativePath, IMinioClient minioClient, string bucketName,
        SearchOption searchOption = SearchOption.TopDirectoryOnly,
        string searchPattern = @"^([\s\S]+)(\.\w+)?$")
    {
        return new SearchMinioFileConfig(rootDirectory, fileGroupName, directoryRelativePath,
            minioClient, bucketName, searchOption, searchPattern);
    }

    /// <summary>
    ///     构建搜索Minio文件夹的配置
    /// </summary>
    /// <param name="directoryFullPath">目录完整路径</param>
    /// <param name="minioClient">Minio客户端</param>
    /// <param name="bucketName">桶名称</param>
    /// <param name="searchOption">搜索选项</param>
    /// <param name="searchPattern">
    ///     模糊查询模式，默认匹配所有文件
    ///     如果想查询指定类型文件使用 ^([\s\S]+)(\.(jpg|png))$
    ///     如果想模糊查询文件使用  ^([\s\S]*)name([\s\S]*)(\.\w+)$
    /// </param>
    /// <returns></returns>
    public static SearchMinioFileConfig BuildSearchMinioFileConfig(this string directoryFullPath,
        IMinioClient minioClient, string bucketName,
        SearchOption searchOption = SearchOption.TopDirectoryOnly,
        string searchPattern = @"^([\s\S]+)(\.\w+)?$")
    {
        return new SearchMinioFileConfig(directoryFullPath, minioClient, bucketName, searchOption, searchPattern);
    }
}